#include "module_mem.h"
#include "esp_heap_caps.h"
#include "esp_log.h"

static const char* TAG = "module_mem";

void *module_mem_calloc(uint32_t size, uint32_t caps)
{
    void * mem = NULL;
    if(NULL == (mem = heap_caps_calloc(1, size, caps))){
        ESP_LOGE(TAG, "heap men callloc fail.");
    }

    return mem;
}

void *module_mem_calloc_psram(uint32_t size)
{
    return module_mem_calloc(size, MALLOC_CAP_SPIRAM);
}

void module_mem_psram_safe_free(void *ptr)
{
    if(NULL != ptr){
        heap_caps_free(ptr);
    }
}

void *module_mem_calloc_dmaram(uint32_t size)
{
    return module_mem_calloc(size, MALLOC_CAP_DMA);
}